<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<script src='design.js'></script>
		<link href="../cssmui/mui.min.css" rel="stylesheet" />
		<script type="text/javascript" src="../mui/common.js"></script>
		<script type="text/javascript" src="dbtools.js"></script>
		<script type="text/javascript" src="../js/jsondb.js"></script>
		<script src="../mui/mui.min.js"></script>

	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">后台管理</h1>

		</header>
		<div class="mui-content">
			表
			<select id="select1" width="120px">
				<option value="all">所有</option>
			</select><br>
			<div class="mui-plus-hidden"> 模型序号
				<select id="select2" width="120px">
					<option value="">请选择</option>
					<option value="0">model</option>
					<option value="1">obj</option>
					<option value="2" selected>get</option>
					<option value="3">put</option>
					<option value="4">select</option>
					<option value="5">引用属性fi[arr]</option>
					<option value="6">测试对象</option>
					<option value="7">template 读取字段</option>
					<option value="8">input id</option>
					<option value="9">vue get</option>
					<option value="10">vue set</option>
				</select><br> 分割
				<select id="select3" width="120px">
					<option value="">请选择</option>
					<option value="0" selected>换行</option>
					<option value="1">逗号+换行</option>
					<option value="2">分号+换行</option>
				</select>
			</div><br>

			<button class="mui-plus-hidden" id="bt1">导出md</button>
			<button id="bt2">重建所有表</button>
			<button id="bt3">重建某表</button>
			<button id="bt4">查询某表</button>
			<button id="bt5">清除某表</button>><br>
			
			<textarea id="text1" rows="20" cols="38"></textarea><br>

		</div>
		<div>
			<button id="bt11">初始化字典</button>

		</div>
		<script type="text/javascript">
			var oSel = document.getElementById("select1");
			for(var i in tablesarr) {
				var oPt = new Option(tablesarr[i], tablesarr[i]); //创建一个option
				oSel.add(oPt); //添加
			}
			modelconfs[0] = "%%field0 :\'\'";
			modelconfs[1] = "%%field0 :%%value";
			modelconfs[2] = "md.%%field0=_FF.%%getV('%%field0');"
			modelconfs[3] = "_FF.%%putV('%%field0',data.%%field0);";
			modelconfs[4] = "%%field0";

			modelconfs[5] = "%%field0[%%value]";
			modelconfs[6] = "%%field0  :\'%%title\',";
			modelconfs[7] = "<%=list[i].%%field0%>"
			modelconfs[8] = "id='%%field0'  %%title";
			modelconfs[9] = "_curmd.%%field0=data.%%field0;"
			modelconfs[10] = "data.%%field0=_curmd.%%field0;"
			document.getElementById("bt1").addEventListener('click', function() {
				var oSel = document.getElementById("select1");
				var omc = document.getElementById("select2");
				var osp = document.getElementById("select3");
				var val = oSel.options[oSel.selectedIndex].value;
				var i = omc.options[omc.selectedIndex].value;
				var sp = osp.options[osp.selectedIndex].value;
				var text1 = document.getElementById("text1");
				if(val == 'all') {
					var s = ''
					for(var j in tablesarr) {
						s = s + tablesarr[j] + ':{\n'
						s = s + createmodel2(tablesconfig1, tablesarr[j], modelconfs[i], sp)
						s = s + '\n},\n\n'
					}
					text1.value = s
				} else {
					var s = createmodel2(tablesconfig1, val, modelconfs[i], sp);
					text1.value = s
				}
			});

			document.getElementById("bt2").addEventListener('click', function() {
				var text1 = document.getElementById("text1");
				text1.value = ini_tables(tablesconfig1);
			});
			document.getElementById("bt3").addEventListener('click', function() {
				var oSel = document.getElementById("select1");
				var table = oSel.options[oSel.selectedIndex].value;
				var text1 = document.getElementById("text1");
				text1.value = droptable(tablesconfig1, table)
				text1.value += createtable(tablesconfig1, table)
			});
			document.getElementById("bt4").addEventListener('click', function() {
				var oSel = document.getElementById("select1");
				var table = oSel.options[oSel.selectedIndex].value;
				if(table == 'all') return;
				var text1 = document.getElementById("text1");
				var tab1 = new XCDBHelp(table);
				var rs = tab1.getList();
				text1.value = rs.length + '\n'
				for(var i = 0; i < rs.length; i++) {
					var row = rs[i];
					text1.value += JSON.stringify(row) + '\n'
				}

			});
			document.getElementById("bt5").addEventListener('click', function() {
				var oSel = document.getElementById("select1");
				var table = oSel.options[oSel.selectedIndex].value;
				if(table == 'all') return;
				var tab1 = new XCDBHelp(table);
				tab1.clear();
			});

			document.getElementById("bt11").addEventListener('click', function() {
				var tbtyps = new XCDBHelp('tb_types');
				var obj = {
					_idkey: 'gclass',
					_data: [{
							value: "1",
							text: "护肤品"
						},
						{
							value: "2",
							text: "化妆品"
						},
						{
							value: "3",
							text: "保湿霜"
						}
					]
				};
				tbtyps.setObj(obj);
			});
			
		</script>
	</body>

</html>